﻿using Kaleida.ServiceMonitor.Model;
using NUnit.Framework;

namespace Kaleida.UnitTests.Model
{
    [TestFixture]
    public class ScriptSourceTests
    {
        [Test]
        public void TestCreateNew()
        {
            var source = ScriptSource.New(@"C:\PathToScript\MyScript.mscr", "Original");
            
            Assert.AreEqual("MyScript", source.Name);
            Assert.IsTrue(source.IsDirty);
            Assert.AreEqual("Original", source.Content);
            Assert.AreEqual("", source.OriginalContent);
        }

        [Test]
        public void TestLoadFromDisk()
        {
            var source = ScriptSource.Load(@"C:\PathToScript\MyScript.mscr", "Original");

            Assert.AreEqual("MyScript", source.Name);
            Assert.IsFalse(source.IsDirty);
            Assert.AreEqual("Original", source.Content);
            Assert.AreEqual("Original", source.OriginalContent);
        }

        [Test]
        public void TestIsDirty()
        {
            var source = ScriptSource.Load(@"C:\PathToScript\MyScript.mscr", "Original");

            Assert.IsFalse(source.IsDirty);
            source.Content = "Modified";

            Assert.IsTrue(source.IsDirty);
            Assert.AreEqual("Modified", source.Content);
            Assert.AreEqual("Original", source.OriginalContent);

            source.ResetOriginalContent();

            Assert.IsFalse(source.IsDirty);

            Assert.AreEqual("Modified", source.Content);
            Assert.AreEqual("Modified", source.OriginalContent);
        }
    }

}
